package com.itfenghuang.day10;


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

//服务端
public class A07_Server {
    public static void main(String[] args) throws IOException {
        // 1. 创建服务器套接字对象
        ServerSocket ss = new ServerSocket(10076);
        // 2. 监听连接
        Socket socket = ss.accept();
        // 3.接受客服端发送的消息  输入流
        InputStream is = socket.getInputStream();
        byte[] bys=new byte[1024];

        //4.返回消息给客户端  输出流
        OutputStream os = socket.getOutputStream();
        while (true){
            int i = is.read(bys);
            System.out.println("客户端:"+new String(bys,0,i));
            os.write(bys,0,i);
            if ("886".equals(i)){
                break;
            }
        }
        socket.close();

    }
}
